#include "Admin.h"

bool Admin::addUser(std::string username, std::string password, std::string department) const
{
    return DataCenter::getInstance().addUser(username, password, department);
}

bool Admin::deleteUser(std::string username) const
{
    return DataCenter::getInstance().deleteUser(username);
}

void Admin::showAllUsers() const
{
    std::vector<User> users = DataCenter::getInstance().getUsers();
    std::cout << std::setw(10) << "UserName"
              << "\tDepartment\n----------------------------" << std::endl;
    if (users.size() != 0)
    {
        for (const User &u : users)
        {
            std::cout << std::setw(10) << u.getUsername() << " \t" << u.getDepartment() << std::endl;
        }
    }
    else
    {
        std::cout << "\t当前没有用户存在" << std::endl;
    }
}

bool Admin::addMeetingRoom(int id, int capacity) const
{
    return DataCenter::getInstance().addMeetingRoom(id, capacity);
}

bool Admin::deleteMeetingRoom(int id) const
{
    return DataCenter::getInstance().deleteMeetingRoom(id);
}

void Admin::showAllMeetingRooms() const
{
    std::cout << std::setw(8) << "Id"
              << "\t" << std::setw(8) << "Capacity"
              << "\t" << std::setw(8) << "User"
              << "\t" << std::setw(8) << "Department" << std::endl;
    std::cout << std::string(60, '-') << std::endl;
    std::vector<MeetingRoom> rooms = DataCenter::getInstance().getMeetingRooms();
    if (rooms.size() != 0)
    {
        for (MeetingRoom &room : rooms)
        {
            std::cout << std::setw(8) << room.getId()
                      << "\t" << std::setw(8) << room.getCapacity()
                      << "\t";
            // std::cout << room.getUser() << std::endl;
            // std::cout << &(User::ERROR_USER) << std::endl;
            if (room.getUser() == nullptr)
            {
                std::cout << std::setw(8) << "【当前空闲，可以预定】";
            }
            else
            {
                std::cout << std::setw(8) << room.getUser()->getUsername()
                          << "\t" << std::setw(8) << room.getUser()->getDepartment();
            }
            std::cout << std::endl;
        }
    }
    else
    {
        std::cout << std::setw(30) << "当前没有会议室" << std::endl;
        std::cout << std::string(60, '-') << std::endl;
    }
}

void Admin::clearAllMeetingRoomsStatus() const
{
    DataCenter::getInstance().clearAllMeetingRoomStatus();
}

std::string Admin::getUsername() const
{
    return _username;
}

Admin::Admin(std::string username, std::string password)
{
    this->_username = username;
    this->_password = password;
}

Admin Admin::ERROR_ADMIN = Admin();